package com.bangda.crm.service.impl;

import java.util.List;

import com.bangda.crm.domain.vo.ChartVo;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.bangda.crm.mapper.CrmStockMapper;
import com.bangda.crm.domain.CrmStock;
import com.bangda.crm.service.ICrmStockService;

/**
 * 库存Service业务层处理
 * 
 * @author fanboshi
 * @date 2023-10-24
 */
@Service
public class CrmStockServiceImpl implements ICrmStockService 
{
    @Autowired
    private CrmStockMapper crmStockMapper;

    /**
     * 查询库存
     * 
     * @param stockId 库存主键
     * @return 库存
     */
    @Override
    public CrmStock selectCrmStockByStockId(Long stockId)
    {
        return crmStockMapper.selectCrmStockByStockId(stockId);
    }

    /**
     * 查询库存列表
     * 
     * @param crmStock 库存
     * @return 库存
     */
    @Override
    public List<CrmStock> selectCrmStockList(CrmStock crmStock)
    {
        return crmStockMapper.selectCrmStockList(crmStock);
    }

    /**
     * 新增库存
     * 
     * @param crmStock 库存
     * @return 结果
     */
    @Override
    public int insertCrmStock(CrmStock crmStock)
    {
        crmStock.setStockDateChanged(DateUtils.getNowDate());
        crmStock.setCreateTime(DateUtils.getNowDate());
        crmStock.setCreateBy(SecurityUtils.getUsername());
        return crmStockMapper.insertCrmStock(crmStock);
    }

    /**
     * 修改库存
     * 
     * @param crmStock 库存
     * @return 结果
     */
    @Override
    public int updateCrmStock(CrmStock crmStock)
    {
        crmStock.setStockDateChanged(DateUtils.getNowDate());
        crmStock.setUpdateTime(DateUtils.getNowDate());
        crmStock.setUpdateBy(SecurityUtils.getUsername());
        return crmStockMapper.updateCrmStock(crmStock);
    }

    /**
     * 批量删除库存
     * 
     * @param stockIds 需要删除的库存主键
     * @return 结果
     */
    @Override
    public int deleteCrmStockByStockIds(Long[] stockIds)
    {
        return crmStockMapper.deleteCrmStockByStockIds(stockIds);
    }

    /**
     * 删除库存信息
     * 
     * @param stockId 库存主键
     * @return 结果
     */
    @Override
    public int deleteCrmStockByStockId(Long stockId)
    {
        return crmStockMapper.deleteCrmStockByStockId(stockId);
    }

    @Override
    public List<ChartVo> selectCrmStockListByChart() {
        List<ChartVo> chartVos = crmStockMapper.selectCrmStockListByChart();
        return chartVos;
    }
}
